var pageAddress = function (a, b, c) {
    var d = {
        disabled: "disabled",
        active: "active",
        events: {
            addressChoose: "click.action.choose.address",
            addressLhref: "click.action.link.address",
            addressAdd: "click.action.add.address",
            addressDel: "click.action.delete.address",
            provinceChoose: "change.action.choose.province",
            cityChoose: "change.action.choose.city",
            districtChoose: "change.action.choose.district",
            streetChoose: "change.action.choose.street",
            transportChoose: "change.action.choose.transport",
            verifyAddress: "click.action.verify.address"
        }
    }, e = {
        address: {
            module: "#address-box",
            list: ".J_address_list",
            lhref: ".J_address_link",
            addn: ".J_address_add",
            del: ".J_address_del"
        },
        addressForm: {module: "#addressForm", submitBtn: "#addressSub"},
        input: {
            province: "#province",
            city: "#city",
            district: "#district",
            street: "#street",
            transportDay: "#transport_day",
            postcode: "#postcode",
            mobile: 'input[name^="mobile"]'
        }
    }, f = {
        address: {
            choose: function (a) {
                g.choose(a, $(this), "choose")
            }, link: function (a) {
                g.link(a, $(this), "change")
            }, addn: function (a) {
                g.addn(a, $(this), "add")
            }, del: function (a) {
                g.del(a, $(this), "del")
            }, verify: function (a) {
                g.formAddressVal(a, $(this), "verify")
            }, province: function (a) {
                g.areaList(a, $(this), "city")
            }, city: function (a) {
                g.areaList(a, $(this), "district")
            }, district: function (a) {
                g.areaList(a, $(this), "street"), g.postcode()
            }, selectStyle: function (a) {
                var b = $(this);
                return 0 !== Number(b.find("option:selected").val()) || b.find("option:selected").val() ? void b.parent().removeClass(d.disabled).addClass("selected") : (b.parent().addClass(d.disabled).removeClass("selected"), !1)
            }, mobileClear: function () {
                var a, b = $(e.input.mobile);
                a = b.val(), b.on("focus", function () {
                    $(this).val().length && $(this).val() == a && b.val("")
                }).on("blur", function () {
                    0 === $(this).val().length && $(this).val(a)
                })
            }
        }, handler: function (a, b) {
            a.stopPropagation(), a.preventDefault(), "touchstart" === a.type && b.off("click")
        }
    }, g = {
        choose: function (a, b, c) {
            "A" != a.target.nodeName && (a.preventDefault(), b.find(".ui-radio").addClass(d.active).parents("li").siblings().find(".ui-radio").removeClass(d.active), location.href = b.data("addressurl"))
        }, link: function (a, b, c) {
            a.preventDefault(), "A" === a.target.nodeName && (location.href = a.target.href)
        }, addn: function (b, c, d) {
            b.preventDefault(), $.when(h.addressGetLimit()).then(function (c) {
                var d = c.data.limit ? c.data.limit : 10;
                $(e.address.module).find("li").length >= d ? (a.autoMars("button", "click", "center_outstrip_addr_count_btn", ""), a.dialogBlack("最多可添加" + d + "个地址<br />请修改或删除现有地址。")) : location.href = b.target.href
            }, function (c) {
                $(e.address.module).find("li").length >= 10 ? (a.autoMars("button", "click", "center_outstrip_addr_count_btn", ""), a.dialogBlack("最多可添加10个地址<br />请修改或删除现有地址。")) : location.href = b.target.href
            })
        }, del: function (b, c, d) {
            if ("A" === b.target.nodeName) {
                var e = {addressId: c.data("address_id")};
                !isNaN(e.addressId) && e.addressId && a.showDialog('<p style="text-align:center">你要删除该地址吗？', {
                    setClass: "ui-modal-doubleBtn",
                    buttons: !0,
                    type: "defined",
                    buttonsCus: [{name: "取消", attribute: !1}, {name: "删除", attribute: !0}],
                    onDoComplete: function (a, b) {
                        b.oncomplete(!1)
                    },
                    onDoCompleteTo: function (b, d) {
                        d.oncomplete(!1), $.when(h.addressDel(e.addressId)).then(function (b) {
                            a.dialogBlack("地址删除成功"), c.parents("li").fadeOut(function () {
                                $(this).remove()
                            })
                        }, function (b) {
                            a.dialogBlack((b || {}).msg || "未知错误，请刷新页面重试")
                        })
                    }
                })
            }
        }, postcode: function () {
            var b = $(e.input.district).val();
            0 == b || "" == b ? a.dialogBlack("请选择区") : $.ajax({
                url: "ajaxapi-getPostCode.html?" + (new Date).getTime(),
                data: "district=" + b,
                type: "POST",
                dataType: "json",
                success: function (b) {
                    "-1" == b.code ? a.dialogBlack("请选择区") : $(e.input.postcode).val(b.zipcode)
                }
            })
        }, areaList: function (b, c, f) {
            var g = $("#addressForm select:gt(0)"), h = g.index(c);
            if (0 === Number(c.find("option:selected").val()) && !c.find("option:selected").val())return g.each(function (a) {
                a > h && (g[a].disabled = !0, g[a].options.length = 1, $(g[a]).parent(".ui-select").addClass("disabled"))
            }), c.parent().removeClass("selected"), !1;
            c.parent().removeClass(d.disabled).addClass("selected");
            var i = c.find("option:selected").val(), j = {
                url: "http://m.vip.com/ajaxapi-address4level.html?s=" + (new Date).getTime(),
                data: {type: f, id: i},
                dataType: "json",
                type: "Get"
            };
            j.error = function () {
                a.dialogBlack("未知错误，请刷新页面重试")
            }, j.success = function (b) {
                if (b && null != b && void 0 != b) {
                    var c = '<option value="">请选择</option>';
                    if ("city" == f) {
                        for (var g = 0; g < b.length; g++)b[g].city_id && b[g].city_name && (c += '<option value="' + b[g].city_id + '">' + b[g].city_name + "</option>");
                        $(e.input.city).parent().removeClass("selected").removeClass(d.disabled), $(e.input.city)[0].disabled = !1, $(e.input.district).html('<option value="">请选择</option>').parent().removeClass("selected").addClass(d.disabled), $(e.input.district)[0].disabled = !0, $(e.input.street).html('<option value="">请选择</option>').parent().removeClass("selected").addClass(d.disabled), $(e.input.street)[0].disabled = !0
                    } else if ("district" == f) {
                        for (var g = 0; g < b.length; g++)b[g].district_id && b[g].district_name && (c += '<option value="' + b[g].district_id + '">' + b[g].district_name + "</option>");
                        $(e.input.district).parent().removeClass("selected").removeClass(d.disabled), $(e.input.district)[0].disabled = !1, $(e.input.street).html('<option value="">请选择</option>').parent().removeClass("selected").addClass(d.disabled), $(e.input.street)[0].disabled = !0
                    } else if ("street" == f)if (b.length > 0) {
                        for (var g = 0; g < b.length; g++)b[g].street_id && b[g].street_name && (c += '<option value="' + b[g].street_id + '">' + b[g].street_name + "</option>");
                        $(e.input.street).parent().removeClass("selected").removeClass(d.disabled), $(e.input.street)[0].disabled = !1
                    } else c = '<option value="-1">无</option>';
                    $("#" + f).html(c)
                } else a.dialogBlack((b || {}).msg || "未知错误，请刷新页面重试")
            }, $.ajax(j)
        }, formValid: function (b, c, d) {
            var e, f = b.curform, g = !0, h = a.validate.util.initConfig(b);
            return "posting" === f[0].status ? !1 : h.postonce && "posted" === f[0].status ? !1 : (f.find("[datatype]").each(function () {
                if (c)return !1;
                if ($(this).is(":hidden") || "dataIgnore" === $(this).data("dataIgnore"))return !0;
                if (!$(this).attr("datatype"))return !1;
                var b = a.validate.util.getValue.call(f, $(this)), d = $(this);
                return h.elem = $(this), h.onEmpty = $(this).attr("emptymsg"), h.onError = $(this).attr("errormsg"), e = a.validate.util.regcheck.call(f, $(this).attr("datatype"), b, $(this), h), "m" === $(this).attr("datatype") && -1 != $(this).val().indexOf("*") && (e.passed = !0, e.type = 3, info = null), e.passed ? void 0 : h.showAllError ? (g && (g = !1), !0) : (d.focus(), $(this).parent(".ui-select").length ? a.flicker($(this).parent().parent(), "ui-note-error", !1, 1, 5, 1) : a.flicker($(this).parent(), "ui-note-error", !1, 1, 5, 1), a.dialogBlack(e.info || "未知错误，请刷新页面重试"), g = !1, !1)
            }), g ? (f[0].status = "posting", d(f)) : !1)
        }, formAddressVal: function (b, c, d) {
            var f = c.parents().prev(), h = {
                elem: c,
                curform: $(e.addressForm.module),
                onCorrect: null,
                elemTxt: c.val(),
                addressId: f.find('input[name="address_id"]').val(),
                filter: f.find('input[name="filter"]').val(),
                flag: f.find('input[name="flag"]').val(),
                mkobj: f.find('input[name="mk"]'),
                key: f.find('input[name="key"]').val(),
                consignee: f.find('input[name="consignee"]').val(),
                provinceId: f.find('select[name="province"] option:selected').val(),
                cityId: f.find('select[name="city"] option:selected').val(),
                districtId: f.find('select[name="district"] option:selected').val(),
                streetId: f.find('select[name="street"] option:selected').val(),
                address: f.find('textarea[name="address"]').val(),
                mobile: f.find(e.input.mobile).val(),
                postcode: f.find(e.input.postcode).val(),
                transportDay: f.find('select[name="transport_day"] option:selected').val(),
                refererParam: f.find('input[name="refererParam"]').val() || "",
                istempuser: c.data("istempuser"),
                type: d,
                marsSead: c.attr("mars_sead")
            };
            a.autoMars("button", "click", h.marsSead), g.formValid(h, !1, function (b) {
                if ("undefined" == h.mkobj || void 0 == h.mkobj)var c = ""; else var c = h.mkobj.val();
                if ($.trim(h.consignee).match(/•/gi) && (f.find('input[name="consignee"]').val(h.consignee.replace(/•+/gi, "·")), h.consignee = f.find('input[name="consignee"]').val()), h.elem.val("").attr("disabled", !0), $("<div />", {"class": "navbar-mask"}).css({
                        height: 44,
                        paddingTop: 0
                    }).html('<img src="view-src/touch/images/common/loading-big.gif" style="width:20px;margin-right:10px;" /> ' + h.elem.attr("data-loading-text")).appendTo(h.elem.parent()), "boolean" == typeof h.istempuser && h.istempuser) {
                    var d = {
                        url: "ajaxapi-adduseraddress.html",
                        data: {
                            consignee: h.consignee,
                            province: h.provinceId,
                            city: h.cityId,
                            district: h.districtId,
                            street: h.streetId,
                            transport_day: h.transportDay,
                            address: h.address,
                            postcode: h.postcode,
                            mobile: h.mobile
                        },
                        dataType: "json",
                        type: "POST"
                    };
                    d.success = function (c) {
                        h.elem.val(h.elemTxt).attr("disabled", !1).next().remove(), b[0].status = "posted", 200 == c.code ? (a.dialogBlack("页面正在跳转"), self.location.href = "cart-checkout.html") : 1 == c.code && c.msg.length > 0 ? a.dialogBlack(c.msg) : -1 == c.code && c.msg.length > 0 && (b[0].status = "normal", a.dialogBlack(c.msg))
                    }, d.error = function () {
                        b[0].status = "normal", h.elem.val(h.elemTxt).attr("disabled", !1).next().remove(), a.dialogBlack((err || {}).msg || "未知错误，请刷新页面重试")
                    }, $.ajax(d)
                } else {
                    var e = {
                        url: "index.php?m=user&act=address&step=save",
                        data: {
                            filter: h.filter,
                            address_id: h.addressId,
                            consignee: h.consignee,
                            province: h.provinceId,
                            city: h.cityId,
                            district: h.districtId,
                            street: h.streetId,
                            transport_day: h.transportDay,
                            address: h.address,
                            postcode: h.postcode,
                            mobile: h.mobile,
                            flag: h.flag,
                            mk: c,
                            key: h.key,
                            refererParam: h.refererParam
                        },
                        dataType: "json",
                        type: "POST"
                    };
                    e.success = function (c) {
                        h.elem.val(h.elemTxt).attr("disabled", !1).next().remove(), b[0].status = "posted", 1 == c.error && c.message.length > 0 ? "default" == ui ? alert(c.message) : a.dialogBlack(c.message) : -1 == c.error && c.url.length > 0 ? (b[0].status = "normal", location.href = c.url) : b[0].status = "normal"
                    }, e.error = function () {
                        b[0].status = "normal", h.elem.val(h.elemTxt).attr("disabled", !1).next().remove(), a.dialogBlack((err || {}).msg || "未知错误，请刷新页面重试")
                    }, $.ajax(e)
                }
            })
        }
    }, h = {
        addressDel: function (b) {
            return a.ajax({
                url: "/ajaxapi-address.html",
                data: {action: "deleteAddr", address_id: b},
                dataType: "json",
                type: "GET"
            })
        }, addressGetLimit: function () {
            return a.ajax({url: "/ajaxapi-address.html", data: {action: "getLimit"}, dataType: "json", type: "GET"})
        }
    }, i = {
        events: function () {
            $(e.address.module).off(d.events.addressChoose, e.address.list).on(d.events.addressChoose, e.address.list, f.address.choose).off(d.events.addressLhref, e.address.lhref).on(d.events.addressLhref, e.address.lhref, f.address.link).off(d.events.addressAdd, e.address.addn).on(d.events.addressAdd, e.address.addn, f.address.addn).off(d.events.addressDel, e.address.del).on(d.events.addressDel, e.address.del, f.address.del), $(e.addressForm.module).off(d.events.verifyAddress, e.addressForm.submitBtn).on(d.events.verifyAddress, e.addressForm.submitBtn, f.address.verify).off(d.events.provinceChoose, e.input.province).on(d.events.provinceChoose, e.input.province, f.address.province).off(d.events.cityChoose, e.input.city).on(d.events.cityChoose, e.input.city, f.address.city).off(d.events.districtChoose, e.input.district).on(d.events.districtChoose, e.input.district, f.address.district).off(d.events.transportChoose, e.input.transportDay).on(d.events.transportChoose, e.input.transportDay, f.address.selectStyle).off(d.events.streetChoose, e.input.street).on(d.events.streetChoose, e.input.street, f.address.selectStyle)
        }
    }, j = {
        init: function () {
            i.events(), $(e.addressForm.module).length && f.address.mobileClear()
        }
    };
    $(function () {
        j.init()
    })
}(hawk, window, void 0);